package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjWorkFieldValOption;
import com.zb.mapper.ZjWorkFieldValOptionMapper;
import com.zb.service.ZjWorkFieldValOptionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 工单字段值附件表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-12-29
 */
@Service
public class ZjWorkFieldValOptionServiceImpl extends ServiceImpl<ZjWorkFieldValOptionMapper, ZjWorkFieldValOption> implements ZjWorkFieldValOptionService {
    @Resource
    private ZjWorkFieldValOptionMapper workFieldValOptionMapper;

    // 根据工单字段值表ID集合查询
    @Override
    public List<ZjWorkFieldValOption> getByWorkFieldValIds(List<Long> workFieldValIds) {
        if (CollectionUtil.isEmpty(workFieldValIds)) {
            return new ArrayList<>();
        }
        // 只取前 100 个 ID
        List<Long> limitedIds = workFieldValIds.stream()
                .limit(100)
                .toList();
        QueryWrapper<ZjWorkFieldValOption> wrapper = new QueryWrapper<>();
        wrapper.select("id", "work_field_val_id", "opt_value");
        wrapper.in("work_field_val_id", limitedIds);
        return this.list(wrapper);
    }

    // 根据工单ID删除工单自定义字段值
    @Override
    public void deleteByWorkId(Long workId) {
        workFieldValOptionMapper.deleteByWorkId(workId);
    }
}
